package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.mapper.DtsGoodsProductMapper;
import com.qf.pojo.DtsGoodsProduct;
import com.qf.service.DtsGoodsProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author ZhangYuJie
 * projectName:shop_manage
 * time:2022/5/17 8:21
 * description:
 */
@Service
public class DtsGoodsProductServiceImpl implements DtsGoodsProductService {

    @Autowired
    DtsGoodsProductMapper dtsGoodsProductMapper;

    @Override
    public int count() {
        QueryWrapper<DtsGoodsProduct> wapper = new QueryWrapper<>();
        wapper.eq("deleted", false);
        Integer count = dtsGoodsProductMapper.selectCount(wapper);
        return count;
    }

    /**
     * 根据商品id查询库存集合
     * @param gid
     * @return
     */
    @Override
    public List<DtsGoodsProduct> queryByGid(Integer gid) {
        QueryWrapper<DtsGoodsProduct> wapper = new QueryWrapper<>();
        wapper.eq("goods_id", gid);
        wapper.eq("deleted", false);
        List<DtsGoodsProduct> list = dtsGoodsProductMapper.selectList(wapper);
        return list;
    }

    /**
     * 添加库存数据
     * @param goodsProduct
     */
    @Override
    public void add(DtsGoodsProduct goodsProduct) {
        goodsProduct.setAddTime(new Date());
        goodsProduct.setUpdateTime(new Date());
        dtsGoodsProductMapper.insert(goodsProduct);
    }

    /**
     * 根据商品id删除库存
     * @param gid
     */
    @Override
    public void deleteByGid(Integer gid) {
        QueryWrapper<DtsGoodsProduct> wapper = new QueryWrapper<>();
        wapper.eq("goods_id", gid);
        dtsGoodsProductMapper.delete(wapper);
    }
}
